package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentController {
    private final ICommentService commentService;

    @Autowired
    public CommentController(ICommentService commentService) {
        this.commentService = commentService;
    }

    /*
        新增评论
        动作:POST
        资源:/comments
        参数:xx=xx&...
     */
    @PostMapping
    public Object save(Comment entity) {
        System.out.println(entity);
        commentService.saveOrUpdate(entity);
        return new JSONResult();
    }

    /*
        查询所有评论
        动作:GET
        资源:/comments/{type}
        参数:
     */
    @GetMapping()
    public Object getComments( @ModelAttribute("qo") CommentQueryObject qo) {
        return commentService.query(qo);
    }

    /*
        查询某个评论
        动作:GET
        资源:/comments/{id}
        参数:
     */
    @GetMapping("/{id}")
    public Object getComment(@PathVariable Long id) {
        return commentService.selectById(id);
    }


}
